{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/common" /}
<fieldset class="layui-elem-field site-demo-button" style="padding:10px;">
	<div class="layui-row">
		<!--  -->
		<form id="form1" class="layui-form layui-form-pane" action="{:url('')}">
			<section class="panel panel-padding">
				<div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-input-inline">
						<input type="text" name="gname" value="{$info.gname|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">介绍</label>
					<div class="layui-input-inline">
						<textarea name="ginfo" placeholder="请输入介绍" class="layui-textarea">{$info.ginfo|default=''}</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">等级</label>
					<div class="layui-input-inline">
						<input type="text" name="glv" value="{$info.glv|default='0'}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-inline">
						<input type="text" name="gsex" value="{$info.gsex|default='0'}" class="layui-input">
					</div>
				</div>
				<fieldset class="layui-elem-field">
					<legend>属性</legend>
					<div class="layui-field-box">
						<div class="layui-row">
							<div class="layui-form-item">
								<label class="layui-form-label">生命</label>
								<div class="layui-input-inline">
									<input type="text" name="ghp" value="{$info.ghp|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">攻击</label>
								<div class="layui-input-inline">
									<input type="text" name="ggj" value="{$info.ggj|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">防御</label>
								<div class="layui-input-inline">
									<input type="text" name="gfy" value="{$info.gfy|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">暴击</label>
								<div class="layui-input-inline">
									<input type="text" name="gbj" value="{$info.gbj|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">吸血</label>
								<div class="layui-input-inline">
									<input type="text" name="gxx" value="{$info.gxx|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">速度</label>
								<div class="layui-input-inline">
									<input type="text" name="gsd" value="{$info.gsd|default='0'}" class="layui-input">
								</div>
							</div>
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>掉落装备</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="gzb">
							<div class="layui-form-item">
								<label class="layui-form-label">几率</label>
								<div class="layui-input-inline">
									<input type="text" name="dljv" value="{$info.dljv|default='1'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">道具</label>
								<button class="layui-btn ajax-mold" data-url="{:url('getMoldList')}" data-type="1" type="button">新增</button>
							</div>
							{foreach name='info.gzb_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="gzb[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="gzb[{$key}][name]" value="[lv:{$vo.lv}]{$vo.name}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNum(this,1)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>掉落道具</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="gdj">
							<div class="layui-form-item">
								<label class="layui-form-label">几率</label>
								<div class="layui-input-inline">
									<input type="text" name="djjv" value="{$info.djjv|default='1'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">道具</label>
								<button class="layui-btn ajax-mold" data-url="{:url('getMoldList')}" data-type="2" type="button">新增</button>
							</div>
							{foreach name='info.gdj_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="gdj[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="gdj[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNum(this,2)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>掉落药品</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="gyp">
							<div class="layui-form-item">
								<label class="layui-form-label">几率</label>
								<div class="layui-input-inline">
									<input type="text" name="ypjv" value="{$info.ypjv|default='1'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">药品</label>
								<button class="layui-btn ajax-mold" data-url="{:url('getMoldList')}" data-type="3" type="button">新增</button>
							</div>
							{foreach name='info.gyp_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="gyp[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="gyp[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNum(this,3)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->

				<div class="layui-input-block">
					<input type="hidden" name="id" type="hidden" value="{$info.id|default=''}">
					<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</section>
		</form>
		<!--  -->
	</div>
</fieldset>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','laydate','upload','element'], function(){
	var $ = layui.jquery
	,laydate = layui.laydate
	,upload = layui.upload
	,element = layui.element
	,form = layui.form;

	$('.ajax-mold').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var type = obj.data('type');
		var title = obj.data('title');

		url = url + '?type=' + type;
		console.log('url',url);

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['500px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='mold'] option:selected");
				var id = $(objb).val();
				var text = $(objb).text();

				console.log('id',id);
				console.log('name',text);
				console.log('type',type);

				addHtml(id,text,type);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		});
	});

	form.render();
});
</script>
<script>
	var gzb_list = "{$gzb_list|default='1'}";
	var gdj_list = "{$gdj_list|default='1'}";
	var gyp_list = "{$gyp_list|default='1'}";

	layui.use(['jquery','form'], function(){
		var $ = layui.jquery
				,form = layui.form;

		window.addHtml = function(id,name,type) {
			console.log('gzb_list',gzb_list);

			var selector = '';
			var key = 1;
			if(type===1){key = gzb_list;selector = 'gzb';}
			if(type===2){key = gdj_list;selector = 'gdj';}
			if(type===3){key = gyp_list;selector = 'gyp';}

			$("#"+selector).append(
					"<div class='layui-form-item'>" +
					"<label class='layui-form-label'>ID</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='"+selector+"["+key+"][id]' value='"+id+"' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<label class='layui-form-label'>名称</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='"+selector+"["+key+"][name]' value='"+name+"' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<button class='layui-btn layui-btn-danger' onclick='delNum(this,"+type+")' type='button'>-</button>" +
					"</div>");

			if(type===1){gzb_list++;}
			if(type===2){gdj_list++;}
			if(type===3){gyp_list++;}
		}

	});

	function delNum(obj,type) {
		var $ = layui.jquery;
		$(obj).parent().remove();

		if(type===1){gzb_list--;}
		if(type===2){gdj_list--;}
		if(type===3){gyp_list--;}
	}
</script>
{/block}